package com.appclient;

import com.raports.RaportMenuWrapperScreenController;
import com.wizardOther.OtherMenuWrapperScreenController;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;

/**
 *
 * @author Sawior
 */
public class MainPanelController implements Initializable {

    private ScreensFramework screensFramework;
    @FXML
    private HBox breadcrumbs;
    @FXML
    private Pane arrow;
    @FXML
    private Pane arrow2;
    @FXML
    private Label text1;
    @FXML
    private Label text2;
    @FXML
    private Label loginPersonLastName;
    @FXML
    private Label loginPersonName;
    @FXML
    private StackPane mainPanel;
    private Scene loginScene;
    private String employeeType;
    private boolean isOtherMenuButtonsShow = false;
    private boolean isRaportMenuButtonsShow = false;
    
    @FXML
    private void backToMenu(ActionEvent event) {
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.MAIN_SCREEN)) {
            showLoginPanel();
        }
        setFirstLevelText("Menu");
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.OTHER_WIZARD_SCREEN)) {
            if (isOtherMenuButtonsShow) {
                screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
            } else {
                screensFramework.getScreensController().setScreen(ScreensFramework.OTHER_WIZARD_SCREEN);
                ((OtherMenuWrapperScreenController) screensFramework.getScreensController().getController(ScreensFramework.OTHER_WIZARD_SCREEN)).setOtherButtonsPanel();
                setFirstLevelText("Inne");
            }
        }
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.RAPORT_WIZARD_SCREEN)) {
            if (isRaportMenuButtonsShow) {
                screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
            } else {
                screensFramework.getScreensController().setScreen(ScreensFramework.RAPORT_WIZARD_SCREEN);
                ((RaportMenuWrapperScreenController) screensFramework.getScreensController().getController(ScreensFramework.RAPORT_WIZARD_SCREEN)).setRaportButtonsPanel();
                setFirstLevelText("Raporty");
            }
        }
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.CLIENT_WIZARD_SCREEN)) {
            screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
        }
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.ENTRY_WIZARD_SCREEN)) {
            screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
        }
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.EXIT_WIZARD_SCREEN)) {
            screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
        }
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.TARRIF_SCREEN)) {
            screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
        }
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.STATE_SCREEN)) {
            screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
        }
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.NEW_CAR_SCREEN)) {
            screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
        }
        if (screensFramework.getScreensController().getActual().equals(ScreensFramework.RECEIVABLES_SCREEN)) {
            screensFramework.getScreensController().setScreen(ScreensFramework.MAIN_SCREEN);
        }

    }

    private void showLoginPanel() {
        try {
            FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("loginPanel.fxml"));
            AnchorPane page = (AnchorPane) loader.load();
            loginScene = new Scene(page);
            LoginController controller = loader.getController();
            Start.stage.setScene(loginScene);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        screensFramework = new ScreensFramework(this);
        mainPanel.getChildren().addAll(screensFramework);
        
    }

    public void setLoginPersonNameAndLastName() {
        loginPersonName.setText(LoginController.PERSON_LOGIN_NAME);
        loginPersonLastName.setText(LoginController.PERSON_LOGIN_LASTNAME);
        employeeType = LoginController.PERSON_LOGIN_JOBTYPE;
    }

    public void setFirstLevelText(String text) {
        text1.setVisible(true);
        text1.setText(text);
        text2.setVisible(false);
        arrow2.setVisible(false);
    }

    public void setSecondLevelText(String text) {
        text2.setText(text);
        text2.setVisible(true);
        arrow2.setVisible(true);
    }
    
    public void setIsOtherMenuButtonsShow(boolean isOtherMenuButtonsShow) {
        this.isOtherMenuButtonsShow = isOtherMenuButtonsShow;
    }

    public String getEmployeeType() {
        return employeeType;
    }

    public void setEmployeeType(String employeeType) {
        this.employeeType = employeeType;
    }
    
    public void setIsRaportMenuButtonsShow(boolean isRaportMenuButtonsShow) {
        this.isRaportMenuButtonsShow = isRaportMenuButtonsShow;
    }

}
